﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace bat_sym.SimulationLogic.Rules
{
    class NaturalDeath : ISimulationRule
    {
        public NaturalDeath()
        {
            RuleName = "Natural Death";
            Parameters.Add("Age Limit (days)", 3600);
        }

        public override void Execute(System.Collections.ObjectModel.ObservableCollection<Models.Bat> bats)
        {
            var dead = new List<Models.Bat>();
            var ageLim = Parameters["Age Limit (days)"];
            foreach (Models.Bat bat in bats)
            {
                bat.Age += 1;
                bat.DaysParent += 1;
                if (bat.Age >= ageLim)
                {
                    bat.alive = false;
                    dead.Add(bat);
                }
            }

            foreach (Models.Bat bat in dead)
            {
                bats.Remove(bat);
            }
        }
    }
}
